<?php
class Info_mdl extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	
	public function getinfo($p_id)
	{
		$strSql = 'SELECT id,info_title,info_author,info_date,info_content From dili_u_m_info WHERE id ='.$p_id;
		$arr    = $this->db->query($strSql)->result_array();
		if (empty($arr))
		{
			return array();
		}
		return $arr[0];
	}
	
	public function getAllInfo($p_begin = 0,$p_page = 10,$p_type = 0,$p_sort = 0)
	{
		if ($p_begin == null)
		{
			$p_begin = 0;
		}
		
		
		if ($p_type == 0)
		{
			$strSql = "select count(id) as icount from dili_u_m_info where info_type = $p_sort group by id limit $p_begin,$p_page";
			$arr = $this->db->query($strSql)->result_array();
			return $arr[0]['icount'];
		}
		else 
		{
			$strSql = "select id, info_title,info_author,info_date,info_content from dili_u_m_info where info_type = $p_sort group by id limit $p_begin,$p_page";
			return $this->db->query($strSql)->result_array();
		}
	}
	
	public function getNextinfoIdById($p_id)
	{
		$nextId = 0;
		$strSql = 'SELECT info_type From dili_u_m_info WHERE id ='.$p_id;
		$arr    = $this->db->query($strSql)->result_array();

		if (empty($arr[0]))
		{
			return $nextId;
		}
		
		
		$strSql2 = "select * from dili_u_m_info where info_type = ".$arr[0]['info_type'];
		
		$arr2    = $this->db->query($strSql2)->result_array();
		$flag = 0;
		foreach ($arr2 as $index => $arr3)
		{
			if ($flag == 1)
			{
				$nextId = $arr3['id'];
				break;
			}
			if ($arr3['id'] == $p_id)
			{
				$flag = 1;
			}
		}
		
		return $nextId;
		
	}
}